/**
 * <pre>
 *     author : XML
 *     e-mail : 946891360@qq.com
 *     time   : 2019/06/10
 *     version:
 *     desc   :
 * </pre>
 */

import {combineReducers} from 'redux'
import theme from './theme'
import popular from './popular'
import trending from './trending'
import {rootCom, RootContainer} from '../navigator/AppNavigator'

//1.指定默认state
const navState = RootContainer.router.getStateForAction(RootContainer.router.getActionForPathAndParams(rootCom));
/**
 * 创建自己的navigation reducer
 * @param state
 * @param action
 * @returns {State | null | State}
 */
const navReducer = (state = navState, action) => {
    const nextState = RootContainer.router.getStateForAction(action, state);
    //如果nextState 为null 或未定义 ,只需要返回原始的state
    return nextState || state;
};
/**
 * 合并 reducer
 * @type {Reducer<any> | Reducer<any, AnyAction>}
 */
const index = combineReducers({
    nav: navReducer,
    theme: theme,
    popular: popular,
    trending: trending
});

export default index;